from django.db import models
from django.core import validators
from django.utils.functional import curry
from nameremoved.helpers import ImageSizeValidator
from random import randint

class Highlight(models.Model):
    image = models.ImageField(upload_to="highlights/",
        help_text="135px wide by 110px tall, please.",
        validator_list=[curry(ImageSizeValidator,width=135,height=110)])
    public = models.BooleanField(default=False)
    
    highlights = models.Manager()
    
    @classmethod
    def random(cls):
        return cls.highlights.all()[randint(0,cls.highlights.all().count()-1)]
    
    class Admin:
        list_filter = ('public',)

    def __unicode__(self):
        return u"%s (%d)" % (self.image, self.public)

class Title(models.Model):
    image = models.ImageField(upload_to="titles/",
        help_text="800px wide by 110px tall, please.",
        validator_list=[curry(ImageSizeValidator,width=800,height=110)],)
    public = models.BooleanField(default=False)
    
    titles = models.Manager()
    
    @classmethod
    def random(cls):
        return cls.titles.all()[randint(0,cls.titles.all().count()-1)]
    
    class Admin:
        list_filter = ('public',)
    
    def __unicode__(self):
        return u"%s (%d)" % (self.image, self.public)